package kz.pdt12.hw.tests;

import kz.pdt12.hw.data.ContactData;
import kz.pdt12.hw.utils.SortedListOf;
import org.testng.annotations.Test;

import java.util.Random;

import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.equalTo;

/**
 * Created with IntelliJ IDEA.
 * User: raimbek
 * Date: 10.03.13
 * Time: 0:22
 */
public class ContactRemovalTest extends TestBase {

    @Test
    public void deleteSomeContact() {
        SortedListOf<ContactData> oldList = app.getModel().getContacts();

        Random random = new Random();
        int index = random.nextInt(oldList.size() - 1);

        app.getContactHelper().deleteContact(index);

        SortedListOf<ContactData> newList = app.getModel().getContacts();

        assertThat(newList, equalTo(oldList));

        if (app.getPropertyKey("check.db").equals("yes")) {
            assertThat(app.getModel().getContacts(), equalTo(app.getHibernateHelper().listContacts()));
        }
        if (app.getPropertyKey("check.ui").equals("yes")) {
            assertThat(app.getModel().getContacts(), equalTo(app.getContactHelper().getUiContacts()));
        }
    }

}
